package com.example.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

// 购物车任务
public class CartActivity extends AppCompatActivity {
    String[] names = new String[]{"中国十大名茶 六安瓜片200g", "俯仰天地系列全自动雨伞", "蓝色军刀AGS反重力减压护脊双肩包"};
    int[] prices = new int[]{149, 328, 469};
    int[] counts = new int[]{2, 1, 1};
    int[] types = new int[]{0, 1, 1};
    int[] images = new int[]{R.drawable.tea, R.drawable.umbrella, R.drawable.bag};

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_cart);

        // 1、定义数据
        List<ProductBean> data = new ArrayList<>();
        for(int i=0; i<3; i++) {
            // 定义商品对象
            ProductBean productBean = new ProductBean(images[i], names[i], prices[i], counts[i], types[i]);
            data.add(productBean);
        }
        // 2、定义Adaper
        CartAdapter adapter = new CartAdapter(
                this,
                R.layout.cart_listview_item,     // 每一行的布局文件
                data
        );
        // 3、关联 adapter与listview
        ListView listView = findViewById(R.id.list_view);
        listView.setAdapter(adapter);
    }
}